function [h,slope,offset,R2,SCE,P,T] = plotlinearfit(Y,X)
%PLOTLINEARFIT - One line description goes here.
%   [h,slope,offset,R2,SCE,P,T] = plotlinearfit(Y,X)
%
%   Example
%       >> plotlinearfit(Y,X)
%
%   See also:

% Author: K. N'Diaye (kndiaye01<at>yahoo.fr)
% Copyright (C) 2008
% This program is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by  the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version: http://www.gnu.org/copyleft/gpl.html
%
% ----------------------------- Script History ---------------------------------
% KND  2008-07-01 Creation
%
% ----------------------------- Script History ---------------------------------

if nargin<1
    error('No data!')
end
switch nargin
    case 0
        error('No input!')
    case 1
        [slope,offset,R2,SCE,P,T] = linearfit(Y);
        X=1:size(Y,1);
    case 2
        [slope,offset,R2,SCE,P,T] = linearfit(Y,X);
end
% [s,o,r2,sce,p]=linearfit(roi.allcons,roi.allregressors);
%     text(median(roi.allregressors), quantile(roi.allcons,.90), {'Correlation: '  sprintf('r2 = %g\np = %g', r2,p)})
%     xlabel(xSPM.SPM.xX.name(find(xSPM.SPM.xCon(Icc).c)))
%     ylabel(xSPM.SPM.xY.VY(1).descrip)
if size(X,2) == 1
    h=plot(X, Y, 'x');
elseif size(X,2) == 2
    for i=1:size(Y,2)
        h(i)=stem(X(:,1),X(:,2),Y(:,i), 'x');
    end
else
end
hold on;
h=h(:);
[xx]=axis;
for i=1:size(Y,2)
    h(i,2)=plot(xx(1:2)', xx(1:2)'*slope(i)+(xx(1:2)'.*0+1)*offset(i), '--', 'Color', get(h(i), 'Color')); hold on
end
hold off


